package com.etop.litepal.db;

import android.util.Log;

import org.litepal.crud.DataSupport;

import java.util.List;

/**
 * Created by John on 2016/1/24.
 */
public class dictDAO  {
    //插入一个关键字
    public void insertKeyword(String name)
    {
        Keyword keyword = new Keyword();
        keyword.setName(name);
    }

    public boolean insertText(String keyName,int seq,String content)
    {
        Keyword keyword = getKeyword(keyName);
        if(keyName!=null)
        {
            Text text = new Text();
            text.setSeq(seq);
            text.setContent(content);
            if(!text.save())
            {
                return false;
            }
            keyword.getText().add(text);
            return keyword.save();
        }
        Log.d("TAG","关键字不存在");
        return false;
    }

    /**
     *获得关键字
     * @param name
     * @return Keyword
     */
    public Keyword getKeyword(String name)
    {
        List<Keyword> keywords =  DataSupport.where("name=?", name).find(Keyword.class);
        if(keywords.isEmpty())
        {
            return null;


        }
        else
        {
            return keywords.get(0);
        }
    }

    /**
     *
     * @param seq
     * @param content
     * @return Text
     */
    public Text generateText(int seq,String content)
    {
        Text text = new Text();
        text.setSeq(seq);
        text.setContent(content);
        return text;
    }

    /**
     *
     * @param seq
     * @param url
     * @return Picture
     */
    public Picture generatePicture(int seq,String url)
    {
        Picture picture = new Picture();
        picture.setSeq(seq);
        picture.setUrl(url);
        return picture;
    }
    public Video generateVideo(int seq,String url)
    {
        Video video = new Video();
        video.setSeq(seq);
        video.setUrl(url);
        return video;
    }
}
